﻿
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmVenta.aspx.cs" Inherits="PharmacyWeb.Ventas.frmVenta" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Panel runat="server" ID="pnlCliente" CssClass="CajaDialogo">
        <div class="panel-success">
            <div class="panel-heading">Clientes</div>
            <div class="panel-body">
                <table>
                    <tr>
                        <td>Criterio:</td>
                        <td><asp:TextBox runat="server" ID="txtCriterioCliente" CssClass="form-control input-sm"></asp:TextBox></td>
                        <td><asp:Button runat="server" ID="btnBuscarPopUP" Text="Buscar" CssClass="btn btn-success"/></td>
                    </tr>
                </table>
                <asp:GridView runat="server" ID="gridCliente" DataKeyNames="DNI"
                    CssClass="table table-bordered" AutoGenerateColumns="False" 
                    DataSourceID="obdsClientes" OnSelectedIndexChanged="gridCliente_SelectedIndexChanged">
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="Id" HeaderText="N°" SortExpression="Id"></asp:BoundField>
                        <asp:BoundField DataField="Nombres" HeaderText="Nombres" SortExpression="Nombres"></asp:BoundField>
                        <asp:BoundField DataField="Apellidos" HeaderText="Apellidos" SortExpression="Apellidos"></asp:BoundField>
                        <asp:BoundField DataField="DNI" HeaderText="DNI" SortExpression="DNI"></asp:BoundField>
                        <asp:BoundField DataField="Direccion" HeaderText="Direccion" SortExpression="Direccion"></asp:BoundField>
                    </Columns>
                </asp:GridView>
                <asp:ObjectDataSource runat="server" ID="obdsClientes" SelectMethod="GetClientesByCriterio" TypeName="PharmacyService.ClienteService" OnObjectCreating="obdsClientes_ObjectCreating">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="txtCriterioCliente" PropertyName="Text" Name="criterio" Type="String"></asp:ControlParameter>
                    </SelectParameters>
                </asp:ObjectDataSource>
            </div>
            <div class="panel-footer"><asp:Button runat="server" ID="btnCancelar" Text="X" CssClass="btn btn-danger btn-sm"/></div>
        </div>
    </asp:Panel>
    .: Liz Vigo :.
    <div class="panel panel-success">
        <div class="panel-heading"><h1>Resgistro de Venta</h1></div>
        <div class="panel-body">
            <div class="col-lg-12">
                <div class="col-lg-6">
                <asp:UpdatePanel runat="server">                    
                	<ContentTemplate>
                	    <table>
                            <tr>
                                <td><label class="control-label">Ruc/Dni: </label></td>
                                <td><asp:TextBox runat="server" ID="txtRucDni" CssClass="form-control input-sm"></asp:TextBox></td>
                                <td><asp:Button Text="..."  runat="server" ID="btnBuscarCliente" CssClass="btn btn-success" OnClick="btnBuscarCliente_Click"/></td>
                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label">Razón Social: </label>
                                </td>
                                <td>
                                    <asp:TextBox runat="server" ID="txtRazonSocial" CssClass="form-control input-sm"></asp:TextBox>
                                    <ajaxToolkit:ModalPopupExtender runat="server"
                                        BackgroundCssClass="FondoAplicacion" CancelControlID="btnCancelar"
                                        PopupControlID="pnlCliente"
                                         DynamicServicePath="" Enabled="True"
                                         TargetControlID="txtRazonSocial"
                                         ID="txtRazonSocial_ModalPopupExtender"></ajaxToolkit:ModalPopupExtender>
                                </td>
                            </tr>
                            <tr>
                                <td><label class="control-label">Dirección: </label></td>
                                <td><asp:TextBox runat="server" ID="txtDireccion" CssClass="form-control input-sm"></asp:TextBox></td>
                            </tr>
                        </table> 
                	</ContentTemplate> 
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBuscar" EventName="Click"/>
                    </Triggers>             
                </asp:UpdatePanel>
                </div>
                <div class="col-lg-6">
                	<fieldset>
                        <legend>Venta</legend>
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                            <ContentTemplate>
                                <table>
                                    <tr>
                                        <td><label class="control-label">Fecha:</label></td>
                                        <td><asp:TextBox runat="server" ID="txtFecha" CssClass="form-control input-sm"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label class="control-label">Total:</label>
                                        </td>
                                        <td><asp:TextBox runat="server" ID="txtTotal" CssClass="form-control input-sm" ReadOnly="True"></asp:TextBox></td>
                                    </tr>
                                </table>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="lvProductos" EventName="ItemCommand"/>
                            </Triggers>
                        </asp:UpdatePanel>
                    </fieldset>
                </div>
            </div>
            
            <div class="col-lg-12">
                <fieldset>
                    <legend>Productos</legend>
                    <table>
                        <tr>
                            <td><label class="control-label">Criterio: </label></td>
                            <td><asp:TextBox runat="server" ID="txtCriterio" CssClass="form-control input-sm"></asp:TextBox></td>
                            <td><asp:Button runat="server" ID="btnBuscar" Text="Buscar" CssClass="btn btn-success"/></td>
                        </tr>
                    </table>
                    <asp:UpdatePanel ID="upProductos" runat="server">
                        <ContentTemplate>
                            <asp:ListView ID="lvProductos" runat="server"  SelectMethod="GetLotes"
                                ItemType="PharmacyBussinesEntities.Lote" OnItemCommand="lvProductos_ItemCommand" >
                                <LayoutTemplate>
                                    <div class="table-responsive">
                                        <table class="table table-hover">
                                            <thead>
                                                <tr>
                                                    <th>Nombres</th>                                                                                                       
                                                    <th>F. Vencimiento</th>
                                                    <th>Precio</th>
                                                    <th>Stock</th>
                                                    <th>Accion</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr id="itemPlaceholder" runat="server"/>
                                            </tbody>
                                        </table>
                                    </div>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td><%# Item.Producto.Nombre %></td>
                                       <%-- <td><%# Item.Producto.Laboratorio.Nombre %></td>--%>
                                        <%--<td><%# Item.Producto.Presentacion.Descripcion %></td>--%>                                        
                                        <td><%# Item.FechaVencimiento.ToShortDateString() %></td>
                                        <td><%# Item.PrecioVenta %></td>
                                        <td><%# Item.Producto.Stock %></td>
                                        <td>
                                            <asp:Button ID="btnAdd" runat="server"
                                                CssClass="btn btn-primary btn-sm"
                                                Text="Agregar"
                                                CommandName="AddProducto"
                                                CommandArgument="<%# Item.Id %>"/>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnBuscar" EventName="Click"/>
                        </Triggers>
                    </asp:UpdatePanel>
                </fieldset>
            </div>
            <div class="col-lg-12">
                <!--DEtalle Venta -->
                <fieldset>
                    <legend>Detalle Venta</legend>
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                        <ContentTemplate>
                        
                            <asp:ListView runat="server" ID="lvDetalleVenta" OnItemCommand="lvDetalleVenta_ItemCommand" >
                                <EmptyDataTemplate>
                                    <table class="table table-hover">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Nombres</th>                                                                                            
                                                <th>Presentacion</th>
                                                <th>Cantidad</th>
                                                <th>Precio</th>
                                                <th>Monto</th>
                                                <th>Accion</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td colspan="8">
                                                    <b>No se han agregado productos a la Venta..!</b>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td><h3>Total:</h3></td>
                                                <td><h3><asp:Label runat="server" ID="lblTotal"></asp:Label></h3></td>
                                                <td></td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </EmptyDataTemplate>
                                <LayoutTemplate>
                                    <table class="table table-hover">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Nombres</th>                                                                                                                                            
                                                <th>Cantidad</th>
                                                <th>Precio</th>
                                                <th>Monto</th>
                                                <th>Accion</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr id="itemPlaceholder" runat="server"/>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <td>
                                                    <asp:Button runat="server" ID="btnActualizarDetalle"
                                                        Text="Actulizar Detalle" CommandName="ActualizarDetalle"/>
                                                </td>
                                                <th></th>
                                                <th></th>
                                                <th></th>
                                                <th></th>
                                                <th><h3>Total:</h3></th>
                                                <th><h3><asp:Label runat="server" ID="lblTotal"></asp:Label></h3></th>
                                                <th></th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td><%# Eval("Lote.Id") %> </td>
                                        <td><%# Eval("Lote.Producto.Nombre")%> </td>
                                        
                                        <%--<td><%# Eval("Lote.Producto.Presentacion.Descripcion")%> </td>--%>
                                        <td><asp:TextBox ID="txtCantidad" Text='<%# Bind("Cantidad","{0:N}") %>' Width="50px" runat="server"/></td>
                                        <td>
                                            <%# Eval("Lote.PrecioVenta") %>
                                        </td>
                                        <td><%# Eval("Monto","{0:N}") %></td>                                                                            
                                        <td>
                                            <asp:Button runat="server" ID="btnQuitar"
                                                Text="Quitar" CssClass="btn btn-danger btn-sm" 
                                                CommandName="QuitarDetalle"
                                                CommandArgument='<%# Eval("IdLote") %>'/>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>

                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="lvProductos" EventName="ItemCommand"/>
                            <asp:AsyncPostBackTrigger ControlID="lvDetalleVenta" EventName="ItemCommand"/>
                            <asp:AsyncPostBackTrigger ControlID="btnGuardar" EventName="Click"/>
                        </Triggers>
                    </asp:UpdatePanel>
                </fieldset>
            </div>
            <table class="table-hover">
                <tr>
                    <td><asp:Button runat="server" ID="btnGuardar" Text="Registrar Venta" CssClass="btn btn-success" OnClick="btnGuardar_Click"/></td>
                    <td>
                        <asp:Button runat="server" ID="btnComprobante" Text="Generar Comprobante" CssClass="btn btn-info" OnClick="btnComprobante_Click"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>
